package com.jn.mvvm2.views;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.jn.mvvm2.R;
import com.jn.mvvm2.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private MainViewModel mainViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        mainViewModel = new ViewModelProvider(this).get(MainViewModel.class);
        binding.setViewModel(mainViewModel);
        binding.setLifecycleOwner(this);

        binding.nextButton.setOnClickListener(v -> {
            String url = binding.urlEditText.getText().toString();

            Intent intent = new Intent(MainActivity.this, InputActivity.class);
            intent.putExtra("url", url);
            startActivity(intent);
        });
    }
}
